$(document).ready(function (){	
	var myInterval = window.setInterval(function(){
		$.ajax({
			type:"GET",
			url:"index/run",
			async:true,
			beforeSend:function loading(){
			},
			success:function(v){
				var data = window.JSON.parse(v);
				//for(var i = 0; i < data.msg.length; i++){
				//	$("#content").append('<p>' + data.msg[i] + '</p>');
				//}
				data.loc.sort(function(){return 0.5 - Math.random()});
				var id1 = -1;
				var id2 = -1;
				if(data.loc.length >= 2){
					id1 = data.loc[0];
					id2 = data.loc[1];
						$.ajax({
						type:"GET",
						url:"index/aichat/id1/"+id1+"/id2/"+id2,
						async:true,
						beforeSend:function loading(){
						},
						success:function(v){
							if(v != null) {
								var arr = v.split("III");
								for(var i = 0;i <robotlist.length;i++) {
									if(robotlist[i].id == id1)
										var name1 = robotlist[i].name;
									if(robotlist[i].id == id2)
										var name2 = robotlist[i].name;
								}
								$("#parkchatview").append(name1 +' : ' + arr[0] + "\n\n");
								$("#parkchatview").append(name2 +' : ' + arr[1] + "\n\n");
								if(userProfile != null){
									if(id1 == userProfile.robot.id || id2 == userProfile.robot.id) {
										document.getElementById("isNew").value = 1;
										document.getElementById("actNew").innerHTML = "<img src=\"./images/new.png\" height=\"18\"/>";
									}									
								}
							}
						},
						error:function(){
						}
					});	
				}
			},
			error:function(){
			}
		});	
	},10000);	
});